package com.company.gxcpc2018;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.stream.Stream;

public class Gxcpc2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt(), m = sc.nextInt(), time = 0, a = 0, b = 0;
            Topic[] topics = Stream.generate(() -> {
                Topic topic = new Topic();
                topic.setTime(sc.nextInt());
                return topic;
            }).limit(n).toArray(Topic[]::new);
            for (int i = 0; i < n; i++) {
                topics[i] = new Topic();
                topics[i].time = sc.nextInt();
            }
            for (int i = 0; i < n; i++) {
                topics[i].score = sc.nextInt();
            }
            Arrays.sort(topics, Comparator.comparingInt(Topic::getTime));
            a = getProgram(m, time, a, topics);
            time = 0;
            Arrays.sort(topics, (o1, o2) -> o2.getScore() - o1.getScore());
            b = getProgram(m, time, b, topics);
            int result = a - b;
            if (result > 0) {
                System.out.println("A");
            } else if (result < 0) {
                System.out.println("B");
            } else {
                System.out.println("SAME");
            }
        }
    }

    private static int getProgram(int m, int time, int a, Topic[] topics) {
        for (Topic topic : topics) {
            if (time + topic.getTime() > m) {
                break;
            }
            time += topic.getTime();
            a += topic.getScore();
        }
        return a;
    }

    public static class Topic {
        private int time;
        private int score;

        public int getTime() {
            return time;
        }

        public void setTime(int time) {
            this.time = time;
        }

        public int getScore() {
            return score;
        }

        public void setScore(int score) {
            this.score = score;
        }

        @Override
        public String toString() {
            return "Topic{" +
                    "time=" + time +
                    ", score=" + score +
                    '}';
        }
    }
}
